package org.example.Server.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

public class TimeUtils {
    public static String add30Minutes(String timestampStr, int minutes) {
        // 定义时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        // 解析字符串为 LocalDateTime
        LocalDateTime dateTime = LocalDateTime.parse(timestampStr, formatter);

        // 添加 30 分钟
        LocalDateTime newDateTime = dateTime.plusMinutes(minutes);

        // 转回字符串格式
        return newDateTime.format(formatter);
    }

    public static Boolean compareTime(String timestampStr, String compareTimeStr) {

        // 将字符串解析为 LocalDateTime 对象
        LocalDateTime time1 = LocalDateTime.parse(timestampStr);
        LocalDateTime time2 = LocalDateTime.parse(compareTimeStr);

        // 对比两个时间的早晚
        if (time1.isBefore(time2)) {
            System.out.println(timestampStr + " 早于 " + compareTimeStr);
            return false;
        } else {
            return true;
        }
    }
}
